//
//  MMMovableImage.m
//  MemeEditor
//
//  Created by Phan Quang Ha on 7/8/13.
//  Copyright (c) 2013 soyo. All rights reserved.
//

#import "MMMovableImage.h"
#import "MMConstants.h"
#import <QuartzCore/QuartzCore.h>

@implementation MMMovableImage

- (id)initWithImage:(UIImage *)img
{
    CGSize imageSize = img.size;
    CGFloat initWidth =  DEFAULT_IMG_WIDTH;
    CGFloat initHeight = imageSize.height * (DEFAULT_IMG_WIDTH - 2)/ imageSize.width + 2;
    
    if (self = [super initWithFrame:CGRectMake(0, 35, initWidth, initHeight)]) {
        self.mImage = img;
    }
    return self;
}

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
    [super drawRect:rect];
    CGRect imgFrame = CGRectMake(1, 1, self.frame.size.width - 2, self.frame.size.height - 2);
    [self.mImage drawInRect:imgFrame blendMode:kCGBlendModeNormal alpha:1.0];
}

- (void)setMImage:(UIImage *)mImage
{
    _mImage = mImage;
    CGSize imageSize = mImage.size;
    CGFloat initWidth =  DEFAULT_IMG_WIDTH;
    CGFloat initHeight = imageSize.height * (DEFAULT_IMG_WIDTH - 2)/ imageSize.width + 2;
    self.frame = CGRectMake(0, 35, initWidth, initHeight);
    [self setNeedsDisplay];
}

@end
